﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using LongQuanWeb.App_Code;

namespace FeiHongWeb.Admin
{
    public partial class News : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if ((this.Session["username"] == null) || (this.Session["username"].ToString() == string.Empty))
            {
                base.Response.Write("<font color=#ff0000 style='FONT-SIZE: 12px'>对不起,您没足够权限访问此页!!</font><br>");
                base.Response.Write("<a href='Login.aspx' target=_top style='FONT-SIZE: 12px'>重新登陆</a><br>");
                base.Response.End();
            }
            if (!IsPostBack)
            {               
                base.Response.Write("<script>parent.window.document.getElementById( 'lbl_title').innerHTML='活动展示'; </script>");
                //string id = Request.QueryString["id"].ToString().Trim();
                string strSql = "Select * From Activity "+ " where subcategorytype = '1'";
                DataTable dt = DbHelperSQL.Query(strSql).Tables[0];
                AspNetPager1.RecordCount = int.Parse(dt.Rows[0][0].ToString());
                BindRpt();
            }
        }

        protected void gv_new_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "up")
            {
                int id = int.Parse(e.CommandArgument.ToString());
                Response.Redirect("NewsAddUpdate.aspx?id=" + id + "&type=2");
            }
            else if (e.CommandName == "del")
            {
                string strSql = "delete from [Activity] where Id=" + int.Parse(e.CommandArgument.ToString().Trim()) + "";
                if (DbHelperSQL.ExecuteSql(strSql) > 0)
                {
                    BindRpt();
                    base.Response.Write("<script>alert('删除成功！');window.location='News.aspx'</script>");
                }
                else
                    base.Response.Write("<script>alert('删除失败！');</script>");
            }
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindRpt();
        }

        private void BindRpt()
        {
            string strSql = "select * from [Activity] where subcategorytype = '1'";
            DataTable dt = DbHelperSQL.GetListDataSet(AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, strSql);
            this.gv_new.DataSource = dt;
            this.gv_new.DataBind();
        }
    }
}